import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter/material.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/NavigationBar.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/TwoLabelItem.dart';
import 'package:heyangkuaidai/FrameWorkModule/Utils/SPUtils.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:permission_handler/permission_handler.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanApplyPage.dart';
class LoanCertificationPage extends StatefulWidget {
  @override
  _LoanCertificationPageState createState() => _LoanCertificationPageState();
}

class _LoanCertificationPageState extends State<LoanCertificationPage> {
  File _image1;
  File _image2;
  final picker = ImagePicker();

  Future getImage() async {
    PermissionStatus permission = await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.camera);
    print('permission$permission');
    Map<PermissionGroup,
        PermissionStatus> permissions = await PermissionHandler()
        .requestPermissions([PermissionGroup.camera]);
    final pickedFile = await picker.getImage(source: ImageSource.camera);

    setState(() {
      if (pickedFile != null) {
        _image1 = File(pickedFile.path);
      } else {
        print('No image selected.');
      }
    });
  }
  Future getImage1() async {
    PermissionStatus permission = await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.camera);
    print('permission$permission');
    Map<PermissionGroup,
        PermissionStatus> permissions = await PermissionHandler()
        .requestPermissions([PermissionGroup.camera]);
    final pickedFile = await picker.getImage(source: ImageSource.camera);

    setState(() {
      if (pickedFile != null) {
        _image2 = File(pickedFile.path);
      } else {
        print('No image selected.');
      }
    });
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 375, height: 667, allowFontScaling: true);
    return Scaffold(
      resizeToAvoidBottomInset: false,
       body:Column(
         children: [
           SizedBox(height: MediaQuery.of(context).padding.top,),
           NavigationBar(false, title: "实名认证",),

           Container(
               width: ScreenUtil.screenWidth,
               height: ScreenUtil().setWidth(515),
               child: ListView(
                 padding: EdgeInsets.only(top: 0),
                 children: [
                   Container(
                     width: ScreenUtil.screenWidth,
                     height: ScreenUtil().setWidth(42.5),
                     padding: EdgeInsets.only(left: ScreenUtil().setWidth(15),top: ScreenUtil().setWidth(13)),
                     child:Text("请认证您的身份证信息",style: TextStyle(fontSize: ScreenUtil().setSp(14),color: Color(0xffA5A5A5)),textAlign: TextAlign.left,) ,
                   ),
                   Container(
                     width: ScreenUtil.screenWidth,
                     height: ScreenUtil().setWidth(191.5),
                     color: Colors.white,
                     child: Row(
                       children: [
                         SizedBox(width:ScreenUtil().setWidth(15) ,),
                         Column(
                           children: [
                             SizedBox(height:ScreenUtil().setWidth(21.5) ,),
                             Container(
                               width: ScreenUtil().setWidth(164),
                               child:Text("身份证人像面",style: TextStyle(fontSize: ScreenUtil().setSp(14),),textAlign: TextAlign.left,),
                             ),
                             SizedBox(height:ScreenUtil().setWidth(11) ,),
                             InkWell(
                               onTap: getImage,
                               child: Stack(
                                 children: [
                                   Container(
                                     width: ScreenUtil().setWidth(164),
                                     height: ScreenUtil().setWidth(117),
                                     child:_image1==null? Image.asset("sources/yy/person.png"):Image.file(_image1),
                                   ),
                                   Positioned(
                                     left: ScreenUtil().setWidth(56),
                                     top:ScreenUtil().setWidth(32.5) ,
                                     child: Container(
                                       width: ScreenUtil().setWidth(52),
                                       height: ScreenUtil().setWidth(52),
                                       child: Image.asset("sources/yy/camera.png"),
                                     ),
                                   )
                                 ],
                               ),
                             )
                           ],
                         ),
                         SizedBox(width:ScreenUtil().setWidth(15) ,),
                         Column(
                           children: [
                             SizedBox(height:ScreenUtil().setWidth(21.5) ,),
                             Container(
                               width: ScreenUtil().setWidth(164),
                               child:Text("身份证国徽面",style: TextStyle(fontSize: ScreenUtil().setSp(14),),textAlign: TextAlign.left,),
                             ),
                             SizedBox(height:ScreenUtil().setWidth(11) ,),
                             InkWell(
                               onTap: getImage1,
                               child: Stack(
                                 children: [
                                   Container(
                                     width: ScreenUtil().setWidth(164),
                                     height: ScreenUtil().setWidth(117),
                                     child:_image2 == null? Image.asset("sources/yy/guohui.png"):Image.file(_image2),
                                   ),
                                   Positioned(
                                     left: ScreenUtil().setWidth(56),
                                     top:ScreenUtil().setWidth(32.5) ,
                                     child: Container(
                                       width: ScreenUtil().setWidth(52),
                                       height: ScreenUtil().setWidth(52),
                                       child: Image.asset("sources/yy/camera.png"),
                                     ),
                                   )
                                 ],
                               ),
                             )
                           ],
                         ),
                       ],
                     ),
                   ),
                   Container(
                     width: ScreenUtil.screenWidth,
                     height: ScreenUtil().setWidth(47),
                     padding: EdgeInsets.only(left: ScreenUtil().setWidth(15),top: ScreenUtil().setWidth(16.2)),
                     child:Text("身份证信息",style: TextStyle(fontSize: ScreenUtil().setSp(14),color: Color(0xffA5A5A5)),textAlign: TextAlign.left,) ,
                   ),
                   TwoLabelItem(title:"姓　名" ,hitText:"章*闯" ,),
                   TwoLabelItem(title:"身份证", hitText: "430103199308176575",),
                   TwoLabelItem(title:"有效期", hitText: "2002.10.10-2022.10.10",),

                   SizedBox(
                     height: ScreenUtil().setWidth(20.5),
                   ),
                   InkWell(
                     onTap: (){
                       if(_image1!=null && _image2!=null){
                         Navigator.push(
                           context,
                           new CupertinoPageRoute(
                             builder: (context) => new LoanApplyPage(),
                           ),
                         );
                       }

                     },
                     child:Container(
                       padding: EdgeInsets.only(left: 20,right: 20),
                       child: Container(
                           decoration: BoxDecoration(
                             borderRadius: BorderRadius.circular(4),
                             color:Color(0xff41A5EE),
                           ),
                           width: ScreenUtil().setWidth(347),
                           height: ScreenUtil().setWidth(44),
                           child:Center(
                             child: Text("下一步",style: TextStyle(fontSize: ScreenUtil().setSp(17),color: Colors.white),textAlign: TextAlign.center,),
                           )
                       ) ,
                     )
                   ),
                   SizedBox(
                     height:ScreenUtil().setWidth(43) ,
                   ),
                   Container(
                     padding: EdgeInsets.only(left: 20,right: 20),
                     child:Container(
                       width: ScreenUtil().setWidth(342),
                       height: ScreenUtil().setWidth(36),
                       child:Text("请注意：一个微信号只能使用一个身份证进行贷款申请，请使用本人证件。",style: TextStyle(fontSize: ScreenUtil().setSp(13),color: Color(0xff929292)),textAlign: TextAlign.left,),
                     ),
                    ),
                 ],
               )
           ) ,

         ],
       ) ,
    );
  }
}

